home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / glimpsehttp / cgi-bin / artbyid < prev    next >
Text File  |  1995-05-16  |  3KB  |  117 lines

  1. #!/usr/local/bin/perl
  2.  
  3. $HTTPD_NEWSHOME="/usr1/paul/news" ;
  4. $HTTPD_HOME="/usr1/paul/httpd" ;
  5.  
  6. $idxdir="$HTTPD_NEWSHOME/groups";
  7.  
  8. #    To support an ISINDEX type search, set query string if given
  9. #    an argument on the command line
  10. $prefix="query=" if ( $#ARGV >= 0 );
  11.  
  12. #    Check that a query has been made
  13. $query = $ENV{'QUERY_STRING'};
  14.  
  15. #    Strip the variables out from the query string,
  16. #    and assign them into variables, prefixed by 'QS_'
  17. @qvars = split( /\&/, $prefix . $query );
  18. foreach (@qvars) {
  19.     split(/=/);
  20.     $fname = $_[0];
  21.     $fvalue = $_[1];
  22.     $fvalue =~ s/\'//g;
  23.     $cmd = "\$QS_$fname = '$fvalue';" ;
  24.     # print ">>>",$cmd,"\n";
  25.     $cmd = eval $cmd if ( $fname =~ /^[a-z_A-Z]\w*$/ );
  26. }
  27. $QS_query =~ s|\+| |g;
  28. $QS_query =~ s|%(\w\w)|sprintf("%c", hex($1))|ge;
  29. $QS_query =~ s|\'|\\\'|g;
  30.  
  31. if ($QS_maxlines =~ /\d+/) {
  32.     $maxlines = $&;
  33. } else {
  34.     $maxlines = 200;
  35. }
  36.  
  37. $id = $QS_query;
  38. if (!$id) {
  39.     print "Content-type: text/html\n\n";
  40.     print "<TITLE>Search for news articles author</TITLE>\n";
  41.     print "<H1>Search for news articles author</H1>\n";
  42.     print "Please specify e-mail address this person posts from:\n";
  43.     print "<ISINDEX>\n";
  44.     exit;
  45. }
  46.  
  47. require "look.pl";
  48.  
  49. $id =~ tr/A-Z/a-z/;
  50. open(INDEX, "$idxdir/by_addr.idx") ||
  51.     die "Cannot open $idxdir/by_addr.idx: $!";
  52. &look(INDEX,$id,undef,"casefold");
  53. undef @result;
  54. # push articles numbers in @result
  55. $artcount = 0;
  56. while (<INDEX>) {
  57.     chop;
  58.     split(/\t/);
  59.     $_[0] =~ tr/A-Z/a-z/;
  60.     last if substr($_[0],0,length($id)) gt $id;
  61.     $artcount++;
  62.     last if $artcount > $maxlines+3;
  63.     push(@result,$_[1]);
  64. }
  65. close INDEX;
  66. if ($#result >= 0) {
  67.     # search succeded - $id is an author
  68.     print "Content-type: text/html\n\n";
  69.     print "<HEAD><TITLE>Articles by $id</TITLE></HEAD>\n";
  70.     print "<BODY><H1>Articles by $id:</H1><OL>\n";
  71.     open(INDEX, "$idxdir/articles.db") ||
  72.         die "Cannot open $idxdir/articles.db: $!";
  73.     $artcount = 0;
  74.     article: foreach $article (@result) {
  75.         &look(INDEX,$article,undef,"casefold");
  76.         $_ = <INDEX>;
  77.         chop;
  78.         s/\&/\&/;
  79.         s/\</\</;
  80.         s/\>/\>/;
  81.         split(/\t/);
  82.         $_[0] =~ tr/A-Z/a-z/;
  83.         last if substr($_[0],0,length($article)) gt $article;
  84.         $artcount++;
  85.         if ($artcount > $maxlines) {
  86.             $artcount = "at least $artcount";
  87.             print "<LI>Limit of $maxlines articles exceeded\n";
  88.             last article;
  89.         }
  90.         print "<LI><A HREF=\"/cgi-bin/article$article\">\n";
  91.         print "$_[4]<BR><I>$_[5]</I></A>\n";
  92.     }
  93.     close INDEX;
  94.     print "</OL><HR>Total of $artcount articles.\n";
  95.     print "<P><a href=\"/cgi-bin/mfinger?$id\">\n";
  96.     print "Look finger on $id</a>\n";
  97.     print "</BODY>\n";
  98. } else {
  99.     # search failed - maybe it's an article ID
  100.     open(INDEX, "$idxdir/by_id.idx") ||
  101.         die "Cannot open $idxdir/by_id.idx: $!";
  102.     &look(INDEX,$id,undef,"casefold");
  103.     $_ = <INDEX>;
  104.     chop;
  105.     split(/\t/);
  106.     $_[0] =~ tr/A-Z/a-z/;
  107.     close INDEX;
  108.     if (substr($_[0],0,length($id)) gt $id) {
  109.         # no luck - redirect to news server
  110.         print "Location: news:$id\n\n";
  111.     } else {
  112.         $ENV{'PATH_INFO'} = $_[1];
  113.         undef $ENV{'QUERY_STRING'};
  114.         exec "$HTTPD_HOME/cgi-bin/article","getart $id";
  115.     }
  116. }
  117.